<template>
  <view class="login">
	  <h1>登陆页面</h1>
    <input type="text" placeholder="用户名" v-model="loginForm.loginname" style="border: 1px solid black"/>
    <input type="password" placeholder="密码" v-model="loginForm.password" style="border: 1px solid black"/>
    <button class="btn" @click="handleLogin">登录</button>
  </view>
</template>

<script>
export default {
  data() {
    return {
      loginForm: {
        loginname: '',
        password: ''
      },
    }
  },
  methods: {
    handleLogin() {
      if (!this.loginForm.loginname || !this.loginForm.password) {
        this.errorMsg = '请填完信息';
        return;
      }
	  uni.request({
	    url: 'http://47.94.6.186:3001/api/user/login',
	    method: 'POST',
		data:this.loginForm,
	    success: res => {
	      console.log(res.data);
		  uni.setStorageSync('token', res.data.data.token);
		  uni.setStorageSync('userid', res.data.data.userid);
		  uni.showToast({ title: '登录成功' });
		  uni.navigateBack(); 
	    }
	  });
    }
  }
}
</script>

<style scoped>
</style>